<?php 
include("../db_connect.php");
include("../class/objName.php");

$display ="";
$status = "";
$pdate = "";
$replace[] = ' ';
$find[] = ',';
$fname 	="";
$lname 	="";
$email  ="";
$ptype 	="";
$txn_id ="";
$delivered ="";

if(isset($_GET['fname'])){
	$fname = mysql_real_escape_string(htmlentities(trim( $_GET['fname'])));
	$fname = str_replace($find, $replace, $fname);
}
if(isset($_GET['lname'])){
	$lname = mysql_real_escape_string(htmlentities(trim( $_GET['lname'])));
	$lname = str_replace($find, $replace, $lname);
}
if(isset($_GET['email'])){
	$email = mysql_real_escape_string(htmlentities(trim( $_GET['email'])));
	$email = str_replace($find, $replace, $email);
}
if(isset($_GET['ptype'])){
	$ptype = mysql_real_escape_string(htmlentities(trim( $_GET['ptype'])));
	$ptype = str_replace($find, $replace, $ptype);
}
if(isset($_GET['txn_id'])){
	$txn_id = mysql_real_escape_string(htmlentities(trim( $_GET['txn_id'])));
	$txn_id = str_replace($find, $replace, $txn_id);
}
if(isset($_GET['delivered'])){
	$delivered = mysql_real_escape_string(htmlentities(trim( $_GET['delivered'])));
	$delivered = str_replace($find, $replace, $delivered);
}

$sql = "SELECT * FROM tblpayment";
$sql .= " WHERE fname like '".$fname."%' "; 

if( $lname !="" ){
	$sql .= " AND lname like '".$lname."%'";
}
if($email !="" ){
	$sql .= " AND email like '".$email."%'";
}
if($ptype !="" ){
	$sql .= " AND lname like '".$lname."%'";
}
if($txn_id !="" ){
	$sql .= " AND txn_id like '".$txn_id."%'";
}
if($delivered !="" ){
	$sql .= " AND delivered like '".$delivered."%'";
}



$sql .=" ORDER BY transaction_id DESC";


$result = mysql_query($sql)or die(mysql_error());


if(mysql_num_rows($result) <1){
	echo '<div style="width:900px; "><h3 style="color:white;">No Item Found</h3></div>';

}
else{

	$display .= "<form id='delivered'> <table class='buyed_reserve_item_data'  border='0' >
	<tr>
		<th id='tbl_head_color' style=' background-color:#ba3e3f; '>Status
		<input type='checkbox' name='checkall' onclick='allbuyed();'/>
		</th>
		<th id='tbl_head_color' style=' background-color:#ba3e3f; '>txn_id</th>
		<th id='tbl_head_color' style=' background-color:#ba3e3f; '>Item Code</th>
		<th id='tbl_head_color' style=' background-color:#ba3e3f; '>Qty</th>
		<th id='tbl_head_color' style=' background-color:#ba3e3f; '>Total Payment</th>
		<th id='tbl_head_color' style=' background-color:#ba3e3f; '>FName</th>
		<th id='tbl_head_color' style=' background-color:#ba3e3f; '>LName</th>
		<th id='tbl_head_color' style=' background-color:#ba3e3f; '>Email</th>
		<th id='tbl_head_color' style=' background-color:#ba3e3f; '>Purchase date</th>
		
	</tr>";



	while($row= mysql_fetch_array($result)){
		if($row['delivered'] == "yes"){
			$status="Yes"; $display .= "<tr class='even'>";
		}
		else{
			$status="No"; $display .= "<tr class='odd'>";
		}
		if(!empty($row['expiration_date'])){
			$pdate = $row['purchase_date']. ''.$row['expiration_date'];
		}
		else{
			$pdate = $row['purchase_date'];
		}
		$display .='
			<td valign="top">'.$status.'<br/>
				<input type="checkbox" class="cd" name="checkbox" value="'.$row['transaction_id'].'">
			</td>
			<td valign="top">'.$row['txn_id'].'</td>
			<td valign="top">'.$row['item_id'].'</td>
			<td valign="top">'.$row['qty'].'</td>
			<td valign="top">'.$row['per_item_total'].'</td>
			<td valign="top">'.$row['fname'] . '</td>
			<td valign="top">'.$row['lname'] .'</td>
			<td valign="top">'.$row['email'].'</td>
			<td valign="top">'.$pdate.'</td>
			
		';
		$display .='</tr>';
		
		
		
	}
	
	
	
	$display .= "</form></table>";


}

echo $display;


?>